<template>
  <div class="internation-wrap" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" :title="$t('config.InternationalSetting')" @newCreate="newCreate" :tableSelectData="tableSelectData" @del="del"></v-tableTitle>
    <GTable ref="table" :hasCheck="true" :hasEdit="true" api="baTranslationList/selectBaTranslationListList" :otherHeight="0" :columnConfig="columnConfig" @selection-change="selectData" @setdialog="setdialog" > </GTable>


      <el-dialog :visible.sync="editModule.flag" :title="editModule.title" top="0" v-dialogDrag :close-on-click-modal="false" width="900px">
          <internationEditor v-if="editModule.flag" :id="editModule.activeId" :data.sync="editModule.data"></internationEditor>
          <div slot="footer" class="editor-footer">
            <el-button type="primary" :disabled="!this.btnPermNameList.includes('EN02080201')&&!this.btnPermNameList.includes('EN02080201')" @click="submitEditor" v-show="submitBtnVisible">{{$t("common.save")}}</el-button>
            <el-button :disabled="!this.btnPermNameList.includes('EN02080202')&&!this.btnPermNameList.includes('EN02080202')" @click="cancel">{{$t("common.cancel")}}</el-button>
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import baseMixin from "@/mixins/BaseMixin";
import internationEditor from "./model/edit.vue";

export default {
name: "serial",
mixins: [baseMixin],
data() {
  return {
    loading: false,
    columnConfig:{menu_id: 1000, menu_code:"InternationalSetting", menu_list_code:"InternationalSetting",},
    tableSelectData: [],
    dialogFlag: false,
    editModule:{
      title:"",
      flag:false,
      activeId:0,
      data:null
    },
  }
},
computed: {
  btnConfig() {
      return [
        {label: this.$t('common.create'), certigier: false||(!this.btnPermNameList.includes('EN02080203')&&!this.btnPermNameList.includes('WM03170101')), invalid: "newCreate"},
        {label: this.$t('common.delete'), certigier: false||(!this.btnPermNameList.includes('EN02080204')&&!this.btnPermNameList.includes('WM03170101')),disabled: true, invalid: "del"},
      ]
  },
  submitBtnVisible(){
    const systemType = this.editModule.data?.numberLevel;
    if(systemType == 11801&&this.$store.state.wms.toUpperCase().includes('WMWHSE')){
      return false
    }
    return true
  }
},
created() {
},
methods: {
  submitEditor(){
    let params = this.editModule.data;
    if (this.editModule.activeId > 0) {
      params.id = this.editModule.activeId;
      this.$post("/baTranslationList/updateBaTranslationList",params).then(res => {
          this.$message.success(this.$tj('config.InternationalSetting','app.upMes'))
          this.cancel();
      })
    }else{
      this.$post("/baTranslationList/insertBaTranslationList",params).then(res => {
          this.$message.success(this.$tj('config.InternationalSetting','app.addMes'))
          this.cancel();
      })
    }
  },
  cancel(){
    this.$refs.table.getTableData();
    this.editModule = {
      title:"",
      flag:false,
      activeId:0,
      data:{}
    }
  },
  newCreate() {
    this.editModule.title = this.$t('config.InternationalSettingAdd');
    this.editModule.data = {};
    this.editModule.activeId = 0;
    this.editModule.flag = true;
  },
  del(data){
    const ids = data.map(item => item.id).join(',');
    this.$post(`/baTranslationList/deleteBaTranslationListByIds/${ids}`).then(res => {
      this.$refs.table.getTableData();
      this.$message.success(this.$tj('config.InternationalSetting','app.delMes'))
    })
  },
  
  //选中的内容
  selectData(data) {
    this.tableSelectData = data;
  },
  //设置弹框
  setdialog(data) {
    this.editModule.title = this.$t('config.InternationalSettingEdit');
    this.editModule.flag = true;
    this.editModule.activeId = data.id;
    this.$post(`/baTranslationList/${data.id}`).then(res => {
        this.editModule.data = res.data;
    })
  },
},
mounted() {
  if (this.$store.state.wms.toUpperCase().includes('WMWHSE')) {
    //仓库级
    this.permissionStatus = false;
    this.saveStatus = this.newStatus = true;
  }
  this.$store.commit("setSkip", {});
  this.$store.commit("setNewFlag", false);
  this.$store.commit("setRouteData", {});
},
watch: {
  dialogFlag(data) {
    if (data === false) {
      this.$store.commit("setSkip", {});
      this.$store.commit("setRouteData", {});
    }
  }
},
components: {
  "v-tableTitle": tableTitle,
  internationEditor
}
};
</script>

<style scoped>
</style>
